package com.daydreaminger.android.usagecontroller.ui.info;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.AppUtils;
import com.daydreaminger.android.usagecontroller.R;
import com.daydreaminger.android.usagecontroller.databinding.AppinfoFragmentInfoBinding;
import com.daydreaminger.android.usagecontroller.ui.basic.AppBaseFragment;

/**
 * 展示APP的详细信息
 *
 * @author : daydreaminger
 * @date : 2020/12/19 10:54
 */
public class AppInfoFragment extends AppBaseFragment<AppinfoFragmentInfoBinding> {
    private static final String TAG = "AppInfoFragment";

    public static final String ARGS_PACKAGE_NAME = "packageName";
    private String packageName = "";

    public AppInfoFragment() {
        super(R.layout.appinfo_fragment_info);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            if (args.containsKey(ARGS_PACKAGE_NAME)) {
                this.packageName = args.getString(ARGS_PACKAGE_NAME);
            }
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    protected void initViewModel() {
        super.initViewModel();
        mToolbarViewModel.setTitleData("应用详细信息");
        mToolbarViewModel.setUpperIconStatusData(true);
    }

    @Override
    protected void initViews() {
        super.initViews();

        setData();
    }

    private void setData() {
        AppUtils.AppInfo appInfo = AppUtils.getAppInfo(packageName);
        if (appInfo != null) {
            mRootViewDataBinding.tvAppName.setText(appInfo.getName());
        }
    }
}
